package com.marvels.approve.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.approve.manager.dto.OpinionTypeDTO;
import com.marvels.approve.manager.service.IOpinionTypeService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**意见类型
 * @author hejie
 */
@RestController
@RequestMapping("approve/opinion_type/service")
public class OpinionTypeController {
	@Autowired
	private IOpinionTypeService opinionTypeService ;
	@RequestMapping("list")
	@ResponseBody
	public MarvelsResultDTO opinionTypeList(@RequestBody(required=false) OpinionTypeDTO opinionTypeDTO){
		try {
			List datas = this.opinionTypeService.findOpinionTypes(opinionTypeDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), datas);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("add")
	@ResponseBody
	public MarvelsResultDTO addOpinionType(@RequestBody OpinionTypeDTO
			entity){
		try {
			this.opinionTypeService.saveOpinionType(entity);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), entity);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
	
	@RequestMapping("modify")
	@ResponseBody
	public MarvelsResultDTO modifyOpinionType(@RequestBody OpinionTypeDTO entity){
		try {
			this.opinionTypeService.saveOpinionType(entity);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), entity);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().warn("marvels_error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("error...",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), null);
		}
	}
}
